From a3eb518dcccaebd0f48c708c189ad2fcb07f0f73 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Sun, 21 Aug 2022 13:50:18 +0200
Subject: fix(comments): load all comments on a post

Previously, only the first 10 comments was loaded. So I update the
fetching method to retrieve all the comments on a post.
Also, I choose to order comments on client side because of a bug
with WPGraphQL.
Finally, I renamed the Comment type to SingleComment to avoid conflict
with existing types.
---
 src/pages/article/[slug].tsx | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'src/pages/article/[slug].tsx')

diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx
index 5036b5b..64610b4 100644
--- a/src/pages/article/[slug].tsx
+++ b/src/pages/article/[slug].tsx
@@ -11,12 +11,12 @@ import {
   getAllArticlesSlugs,
   getArticleBySlug,
 } from '@services/graphql/articles';
-import { getPostComments } from '@services/graphql/comments';
+import { getAllComments } from '@services/graphql/comments';
 import styles from '@styles/pages/article.module.scss';
 import {
   type Article,
-  type Comment,
   type NextPageWithLayout,
+  type SingleComment,
 } from '@ts/types/app';
 import { loadTranslation, type Messages } from '@utils/helpers/i18n';
 import {
@@ -40,7 +40,7 @@ import { HTMLAttributes } from 'react';
 import { useIntl } from 'react-intl';
 
 type ArticlePageProps = {
-  comments: Comment[];
+  comments: SingleComment[];
   post: Article;
   slug: string;
   translation: Messages;
@@ -239,7 +239,7 @@ export const getStaticProps: GetStaticProps<ArticlePageProps> = async ({
   params,
 }) => {
   const post = await getArticleBySlug(params!.slug as PostParams['slug']);
-  const comments = await getPostComments(post.id as number);
+  const comments = await getAllComments({ contentId: post.id as number });
   const translation = await loadTranslation(locale);
 
   return {
-- 
cgit v1.2.3

